.data 0x0000

.text 0x0000

start: 
		lui $1,0xFFFF
        ori $28, $1, 0xF000
        
		lui $20, 0x8000
       	ori $8,  $0, 0x0001
        ori $9,  $0, 0x0002
        ori $10, $0, 0x0003

        ori $11, $0, 0x0060
        ori $12, $0, 0x0080  # the leftest one
        ori $13, $0, 0x00a0
        ori $14, $0, 0x00c0  #left two switches
        ori $15, $0, 0x00e0
        
        ori $2, $0, 0x0000   #2 is the operator
        ori $3, $0, 0x0001   #3 is the first number,  +1 per loop
        ori $4, $0, 0x0002   #4 is the second number, +3 per loop
        
        ori $5, $0, 0x0009   #5, the number 9
        ori $6, $0, 0x0003   #6, the number 3
        

loop:
	lw   $22,0xC72($28)
	beq  $22, $12, get_answer
	
	addi $2, $2, 1
	addi $3, $3, 1
	addi $4, $4, 3
	
	slt  $17, $5, $4
	bne  $17, $0, mod1
	
	slt  $18, $5, $3
	bne  $18, $0, mod2

	slt  $19, $6, $2 
	bne  $19, $0, mod3

	j loop
	
mod1:
	sub $4, $4, $5
	
	slt  $18, $5, $3
	bne  $18, $0, mod2

	slt  $19, $6, $2 
	bne  $19, $0, mod3
	j loop
	
mod2:
	sub $3, $3, $5
	
	slt  $19, $6, $2 
	bne  $19, $0, mod3
	j loop
	
mod3:
	sub $2, $2, $6
	j loop
	
get_answer:    #7, the operating answer
	beq $2, $0, plus
	beq $2, $8, minus
	beq $2, $9, bit_and
	beq $2, $10, bit_or
	
plus:
	add $7, $3, $4
	j get_question
	
minus:
	slt $21, $3, $4
	beq $21, $8, change
	sub $7, $3, $4
	j get_question

change:
	or $24, $3, $0   #24 is the temp
	or $3, $4, $0
	or $4, $24, $0
	sub $7, $3, $4
	j get_question

	
bit_and:
	and $7, $3, $4
	j get_question
	
bit_or:
	or $7, $3, $4
	j get_question
	
get_question:

	sll $3, $3, 4
	add $3, $3, $2 
	sll $3, $3, 4
	add $3, $3, $4
	
	sw $3, 0xC73($28)      # question to FC73

	sw $0, 0xC62($28)

	j answer
	
answer:
	lw   $22, 0xC72($28)
	bne $22, $14, answer
	lw $23, 0xC70($28)
	beq $23, $7, ans_true
	j ans_false
	
ans_true:
	ori $16, $0, 0x0001
	sw $16, 0xC75($28)
	j next_loop
	
ans_false:
	ori $16, $0, 0x0000     #20210520: changed false to 0, sw to FFFFFC75
	sw $16, 0xC75($28)
	j next_loop

next_loop:
	ori $3, $0, 0x0001
	j loop

	
	
	
        
        
        
        
